package com.rljk.utils;

import com.rljk.domain.common.PageData;
import lombok.extern.slf4j.Slf4j;
import org.codehaus.jackson.map.util.JSONPObject;

import java.util.Map;


/** 接口参数校验
 * 修改日期：2015/11/2
 */
@Slf4j
public class AppUtil  {
	
	/**检查参数是否完整
	 * @param method
	 * @param pd
	 * @return
	 */
	public static boolean checkParam(String method, PageData pd){
		boolean result = false;
		
		int falseCount = 0;
		String[] paramArray = new String[20];
		String[] valueArray = new String[20];
		String[] tempArray  = new String[20];  //临时数组
		
		 if("addCaidan".equals(method)){//后台添加菜单
				paramArray = Const.ADDCAIDAN_PARAM_ARRAY;
				valueArray = Const.ADDCAIDAN_VALUE_ARRAY;
		 }else if("delCaidan".equals(method)){//后台删除菜单
				paramArray = Const.DELCAIDAN_PARAM_ARRAY;
				valueArray = Const.DELCAIDAN_VALUE_ARRAY;
		 }else if("appRegisterUser".equals(method)){//APP用户注册
				paramArray = Const.APPREGISTERUSER_PARAM_ARRAY;
				valueArray = Const.APPREGISTERUSER_VALUE_ARRAY;
		 }else if("APPLoginUser".equals(method)){//APP用户登录
			 paramArray = Const.APPLOGINRUSER_PARAM_ARRAY;
			 valueArray = Const.APPLOGINRUSER_VALUE_ARRAY;
		 }else if("editCaidan".equals(method)){//后台修改菜单
			 paramArray = Const.EDITCAIDAN_PARAM_ARRAY;
			 valueArray = Const.EDITCAIDAN_VALUE_ARRAY;
		 }else if("queryUser".equals(method)){//后台查询用户信息
			 paramArray = Const.QUERYUSER_PARAM_ARRAY;
			 valueArray = Const.QUERYUSER_VALUE_ARRAY;
		 }else if("caidanById".equals(method)){//通过caidanId获取数据
			 paramArray = Const.CAIDANINFO_PARAM_ARRAY;
			 valueArray = Const.CAIDANINFO_VALUE_ARRAY;
		 }else if("caidanListAll".equals(method)){//后台菜单列表（全部）
			 paramArray = Const.CAIDANLISTALL_PARAM_ARRAY;
			 valueArray = Const.CAIDANLISTALL_VALUE_ARRAY;
		 }else if("useridParam".equals(method)){//任务页面显示接口
			 paramArray = Const.TASKSHOWVIEW_PARAM_ARRAY;
			 valueArray = Const.TASKSHOWVIEW_VALUE_ARRAY;
		 }else if("updLocation".equals(method)){//更新用户经纬度接口
			 paramArray = Const.UPDLOCATION_PARAM_ARRAY;
			 valueArray = Const.UPDLOCATION_VALUE_ARRAY;
		 }else if("getNewsDetail".equals(method)){//获取新闻详情
			 paramArray = Const.NEWSDETAIL_PARAM_ARRAY;
			 valueArray = Const.NEWSDETAIL_VALUE_ARRAY;
		 }else if("getBroadCast".equals(method)){//app根据导航栏显示轮播图
			 paramArray = Const.BROADCAST_PARAM_ARRAY;
			 valueArray = Const.BROADCAST_VALUE_ARRAY;
		 }else if("taskInfo".equals(method)){//后台查看单个任务详细
			 paramArray = Const.TASKINFO_PARAM_ARRAY;
			 valueArray = Const.TASKINFO_VALUE_ARRAY;
		 }else if("homeInfo".equals(method)){//后台查看单个首页详细
			 paramArray = Const.HOMEINFO_PARAM_ARRAY;
			 valueArray = Const.HOMEINFO_VALUE_ARRAY;
		 }else if("couponUserListByUserId".equals(method)){//用户优惠券列表
			 paramArray = Const.COUPONUSERLISTBYUSERID_PARAM_ARRAY;
			 valueArray = Const.COUPONUSERLISTBYUSERID_VALUE_ARRAY;
		 }else if("couponList".equals(method)){//优惠券列表
			 paramArray = Const.LISTALL_PARAM_ARRAY;
			 valueArray = Const.LISTALL_VALUE_ARRAY;
		 }else if("getTaskCenter".equals(method)){//app任务中心获取我发布的和我接受的任务
			 paramArray = Const.TASKCENTER_PARAM_ARRAY;
			 valueArray = Const.TASKCENTER_VALUE_ARRAY;
		 }else if("getOrderInfo".equals(method)){//app购物中心获取订单信息
			 paramArray = Const.ORDERINFO_PARAM_ARRAY;
			 valueArray = Const.ORDERINFO_VALUE_ARRAY;
		 }else if("addWealthValue".equals(method)){//app获取财富（能量值，XW链，积分，幸运钻）
			 paramArray = Const.GETWEALTHVALUE_PARAM_ARRAY;
			 valueArray = Const.GETWEALTHVALUE_VALUE_ARRAY;
		 }else if("addTask".equals(method)){//app发布任务
			 paramArray = Const.ADDTASK_PARAM_ARRAY;
			 valueArray = Const.ADDTASK_VALUE_ARRAY;
		 }else if("addMailInfo".equals(method)){//后台添加邮箱信息
			 paramArray = Const.ADDMAILINFO_PARAM_ARRAY;
			 valueArray = Const.ADDMAILINFO_VALUE_ARRAY;
		 }else if("registerUser".equals(method)){//后台注册用户
			 paramArray = Const.REGISTERUSER_PARAM_ARRAY;
			 valueArray = Const.REGISTERUSER_VALUE_ARRAY;
		 }else if("userLoginPhone".equals(method)){//后台发送短信验证码
			 paramArray = Const.SENDMSGCODE_PARAM_ARRAY;
			 valueArray = Const.SENDMSGCODE_VALUE_ARRAY;
		 }else if("loginUser".equals(method)){//后台用户登录
			 paramArray = Const.LOGINRUSER_PARAM_ARRAY;
			 valueArray = Const.LOGINRUSER_VALUE_ARRAY;
		 }else if("APPLoginUser".equals(method)){//APP用户登录
			 paramArray = Const.IN_USERPHONELOGIN_PARAM_ARRAY;
			 valueArray = Const.IN_USERPHONELOGIN_VALUE_ARRAY;
		 }else if("addAgent".equals(method)){//后台申请代理商接口
			 paramArray = Const.ADDAGENT_PARAM_ARRAY;
			 valueArray = Const.ADDAGENT_VALUE_ARRAY;
		 }else if("clickXWStone".equals(method)){//宝石矿点击收取宝石
			 paramArray = Const.CLICKXWSTONE_PARAM_ARRAY;
			 valueArray = Const.CLICKXWSTONE_VALUE_ARRAY;
		 }else if("getDotAgree".equals(method)){//app点赞功能
			 paramArray = Const.DOTAGREE_PARAM_ARRAY;
			 valueArray = Const.DOTAGREE_VALUE_ARRAY;
		 }else if("getIsDotAgree".equals(method)){//app是否点赞功能
			 paramArray = Const.ISDOTAGREE_PARAM_ARRAY;
			 valueArray = Const.ISDOTAGREE_VALUE_ARRAY;
		 }else if("showView".equals(method)){//app首页显示接口
			 paramArray = Const.SHOWVIEW_PARAM_ARRAY;
			 valueArray = Const.SHOWVIEW_VALUE_ARRAY;
		 }else if("getForward".equals(method)){//app转发数量
			 paramArray = Const.GETFORWARD_PARAM_ARRAY;
			 valueArray = Const.GETFORWARD_VALUE_ARRAY;
		 }else if("getTaskCenter".equals(method)){//app任务中心获取我发布的和我接受的任务
			 paramArray = Const.TASKCENTER_PARAM_ARRAY;
			 valueArray = Const.TASKCENTER_VALUE_ARRAY;
		 }else if("commentList".equals(method)){//获取评论列表
			 paramArray = Const.COMMENTLIST_PARAM_ARRAY;
			 valueArray = Const.COMMENTLIST_VALUE_ARRAY;
		 }else if("addComment".equals(method)){//添加评论
			 paramArray = Const.ADDCOMMENT_PARAM_ARRAY;
			 valueArray = Const.ADDCOMMENT_VALUE_ARRAY;
		 }else if("resetPW".equals(method)){//密码重置
			 paramArray = Const.RESETPW_PARAM_ARRAY;
			 valueArray = Const.RESETPW_VALUE_ARRAY;
		 }else if("getCaidanNotice".equals(method)){//通过类型获取公告等列表接口
			 paramArray = Const.GETCAIDANNOTICE_PARAM_ARRAY;
			 valueArray = Const.GETCAIDANNOTICE_VALUE_ARRAY;
		 }else if("getNoticeInfo".equals(method)){//获取通知列表
			 paramArray = Const.GETNOTICEINFO_PARAM_ARRAY;
			 valueArray = Const.GETNOTICEINFO_VALUE_ARRAY;
		 }else if("allComment".equals(method)){//通过文章ID获取相关评论
			 paramArray = Const.ALLCOMMENT_PARAM_ARRAY;
			 valueArray = Const.ALLCOMMENT_VALUE_ARRAY;
		 }else if("editIsShow".equals(method)){//修改评论是否显示
			 paramArray = Const.EDITCOMMENTISSHOW_PARAM_ARRAY;
			 valueArray = Const.EDITCOMMENTISSHOW_VALUE_ARRAY;
		 }else if("editNoticeIsShow".equals(method)){//修改通知是否显示
			 paramArray = Const.EDITNOTICEISSHOW_PARAM_ARRAY;
			 valueArray = Const.EDITNOTICEISSHOW_VALUE_ARRAY;
		 }else if("addNotice".equals(method)){//添加通知
			 paramArray = Const.ADDNOTICE_PARAM_ARRAY;
			 valueArray = Const.ADDNOTICE_VALUE_ARRAY;
		 }else if("editNotice".equals(method)){//修改通知
			 paramArray = Const.EDITNOTICE_PARAM_ARRAY;
			 valueArray = Const.EDITNOTICE_VALUE_ARRAY;
		 }else if("backCaiDan".equals(method)){//后台获取菜单信息
			 paramArray = Const.BACKCAIDAN_PARAM_ARRAY;
			 valueArray = Const.BACKCAIDAN_VALUE_ARRAY;
		 }else if("getAppOrPublicNum".equals(method)){//获取热推app下载或者公众号推荐
			 paramArray = Const.APPPULBICNUMBER_PARAM_ARRAY;
			 valueArray = Const.APPPULBICNUMBER_VALUE_ARRAY;
		 }else if("getAppOrPublicNumDetail".equals(method)){//获取热推app下载或者公众号推荐详情
			 paramArray = Const.APPPULBICNUMBERDET_PARAM_ARRAY;
			 valueArray = Const.APPPULBICNUMBERDET_VALUE_ARRAY;
		 }else if("findCommentListByUserId".equals(method)){//通过用户ID获取自己所属文章的评论列表
			 paramArray = Const.USERCOMMENTLIST_PARAM_ARRAY;
			 valueArray = Const.USERCOMMENTLIST_VALUE_ARRAY;
		 }else if("getDotAgreeByUserID".equals(method)){//通过用户ID统计有哪些人点赞过该用户的文章
			 paramArray = Const.GETDOTAGREEBYUSERID_PARAM_ARRAY;
			 valueArray = Const.GETDOTAGREEBYUSERID_VALUE_ARRAY;
		 }else if("candyExchange".equals(method)){//app任务糖果兑换
			 paramArray = Const.CANDYEXCHANGE_PARAM_ARRAY;
			 valueArray = Const.UCANDYEXCHANGE_VALUE_ARRAY;
		 }else if("getProjectSurveyById".equals(method)){//根据项目库id获取项目概况
			 paramArray = Const.PROJECTSURVEY_PARAM_ARRAY;
			 valueArray = Const.PROJECTSURVEY_VALUE_ARRAY;
		 }else if("getQuesDetailById".equals(method)) {//通过ID获取问卷详情列表
			 paramArray = Const.QUESTIONDATAILBYID_PARAM_ARRAY;
			 valueArray = Const.QUESTIONDATAILBYID_VALUE_ARRAY;
		 }else if("addQuesDetail".equals(method)) {//用户提交问卷列表
			 paramArray = Const.ADDQUESTIONDATAIL_PARAM_ARRAY;
			 valueArray = Const.ADDQUESTIONDATAIL_VALUE_ARRAY;
		 }



	 
		
		int size = paramArray.length;
		for(int i=0;i<size;i++){
			String param = paramArray[i];
			if(!pd.containsKey(param)){
				tempArray[falseCount] = valueArray[i]+"--"+param;
				falseCount += 1;
			}
		}
		if(falseCount>0){
			log.error(method+"接口，请求协议中缺少 "+falseCount+"个 参数");
			for(int j=1;j<=falseCount;j++){
				log.error("   第"+j+"个："+ tempArray[j-1]);
			}
		} else {
			result = true;
		}
		
		return result;
	}

	/**
	 * @param pd
	 * @param map
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static Object returnObject(PageData pd, Map map){
		if(pd.containsKey("callback")){
			String callback = pd.get("callback").toString();
			return new JSONPObject(callback, map);
		}else{
			return map;
		}
	}

}
